
new Vue({
    el: '#app',
    delimiters:['[[', ']]'],

    data: {
        animojis: [],
    },

    methods: {
        /**
         * 请求动态表情列表
         */
        requestAnimojiList() {
            let url = "{% url 'gma:api_get_animoji_list' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.animojis = data;

                this.animojis.forEach(animoji => {
                    animoji.edit_url = `/gma/config/animoji/${animoji.id}/edit/`;
                });
            });
        },

        /**
         * 点击动态表情图标
         * @param animoji
         */
        clickAnimoji(animoji) {
            if (animoji.enabled === 1) {
                this.disableAnimoji(animoji.id);
            } else {
                this.enableAnimoji(animoji.id);
            }
        },

        /**
         * 启动态表情用
         *
         * @param animoji_id
         */
        enableAnimoji(animoji_id) {
            let data = {
                'animoji_id': animoji_id,
            };

            let url = "{% url 'gma:api_enable_animoji' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功开启');
                this.requestAnimojiList();
            });
        },

        /**
         * 禁动态表情用
         * @param animoji_id
         */
        disableAnimoji(animoji_id) {
            let data = {
                'animoji_id': animoji_id,
            };

            let url = "{% url 'gma:api_disable_animoji' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功关闭');
                this.requestAnimojiList();
            });
        },
    },

    mounted() {
        this.requestAnimojiList();
    },
});
